{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 54
    },
    "colab_type": "code",
    "id": "udcj-PssnaVN",
    "outputId": "e5ca3e61-7fbe-4693-e250-8f9752807d1c"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3.128, 3.136, 3.1253333333333333, 3.137, 3.1448, 3.1486666666666667, 3.149714285714286, 3.144, 3.1413333333333333]\n",
      "[-0.013592653589793002, -0.005592653589792995, -0.01625932025645982, -0.004592653589793105, 0.003207346410206924, 0.007074013076873609, 0.008121632124492795, 0.002407346410207012, -0.00025932025645980517]\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "import random\n",
    "random.seed(0)\n",
    "\n",
    "def approximate_pi():\n",
    "    total_points = 0\n",
    "    within_circle = 0\n",
    "    for i in range (10001):\n",
    "        x = random.random()\n",
    "        y = random.random()\n",
    "        total_points += 1\n",
    "        distance = math.sqrt(x**2+y**2)\n",
    "        if distance < 1:\n",
    "            within_circle += 1\n",
    "        if total_points % 1000 == 0:\n",
    "            pi_estimate = 4 * within_circle / total_points\n",
    "            if total_points == 10000:\n",
    "                return pi_estimate\n",
    "            else:\n",
    "                yield pi_estimate\n",
    "\n",
    "estimates = [estimate for estimate in approximate_pi()]\n",
    "errors = [estimate - math.pi for estimate in estimates]\n",
    "\n",
    "print(estimates)\n",
    "print(errors)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "name": "Activity03.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
